package com.example.module_home

import android.view.View
import android.widget.Toast
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.module_common.app.BaseApp
import com.example.module_common.arouter.RouterURLS
import com.example.module_common.base.BaseActivity
import com.example.module_common.model.ArticleListModel
import com.example.module_common.model.BannerModel
import com.example.module_common.utils.ACache
import com.example.module_home.presenter.HomePresenter
import com.example.module_home.view.HomeView
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
import java.util.*


@Route(path = RouterURLS.HOME_ACTIVITY)
class HomeActivity : BaseActivity<HomePresenter>(),HomeView {
    private var bannerModel: List<BannerModel>? = null
    private var mCache: ACache? = null
    private var jsonArray: JSONArray? = null

    override val layoutId: Int
        get() = R.layout.activity_home

    override fun createPresenter(): HomePresenter {
        return HomePresenter(this)
    }

    override fun initView() {
        mCache = ACache.get(BaseApp.context)
        presenter!!.banner()
    }


    override fun addListener() {
    }

    override fun onLoadBanner(data: List<BannerModel>) {
        val list = ArrayList<String>()
        for (m in data) {
            list.add(m.imagePath!!)
        }
        bannerModel = data
        try {
            for (m in data) {
                list.add(m.imagePath!!)
            }
        jsonArray = JSONArray()
        val yosonJsonObject = JSONObject()

            yosonJsonObject.put("name", list[0].length)
            yosonJsonObject.put("age", list[0].length)
            jsonArray!!.put(yosonJsonObject)
        } catch (e: JSONException) {
            e.printStackTrace()
        }
    }

    /**
     * 点击save事件
     *
     * @param v
     */
    fun save(v: View?) {
        mCache!!.put("testJsonArray", jsonArray)
    }


    override fun onLoadArticleList(data: List<ArticleListModel>) {
    }

    override fun showLoading() {
    }

    override fun hideLoading() {
    }
}
